package net.hombrecero.bigbeat.util;

import net.hombrecero.bigbeat.dao.ProjectDAO;
import net.hombrecero.bigbeat.dao.SubSetDAO;
import net.hombrecero.bigbeat.model.Project;
import net.hombrecero.bigbeat.model.SubSet;

import org.springframework.dao.DataAccessException;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;



public class ProjectInsertTest extends AbstractTransactionalDataSourceSpringContextTests {
    //#####################################################################################
    //# objetos de utilidad ESPECIFICOS
    private SubSetDAO  subSetDAO;
    private ProjectDAO projectDAO;


    //#####################################################################################
  //# funciones para ejecucion
  public static void main( String[] args ) {
        junit.textui.TestRunner.run( ProjectInsertTest.class );
    }

  public ProjectInsertTest() {
    super();
    this.setDefaultRollback( false );  //TODO 4apolo ajustar esto!!!!!
  }

  public ProjectInsertTest( String arg0 ) {
    super( arg0 );
    this.setDefaultRollback( false );  //TODO 4apolo ajustar esto!!!!!
  }



    //#####################################################################################
  //# funciones necesarias a implementar para el soporte AbstractTransactionalDataSourceSpringContextTests

  protected String[] getConfigPaths(){
    String[] ret = new String[]{  "applicationContext-jdbc.xml",
                                  "applicationContext-dao.xml"    };
    return ret;
  }

    public void setSubSetDAO( SubSetDAO subSetDAO ) {
    this.subSetDAO = subSetDAO;
  }

    public void setProjectDAO( ProjectDAO projectDAO ) {
    this.projectDAO = projectDAO;
  }



    //#####################################################################################
  //# tests
  public void testStore() {
      try {
        Project project = new Project();
        project.setName( "aaa" );
        project.setAlias( "iii" );
        project.setDescription( "szzzz" );
        project.setUrlWeb( "aaa" );
        project.setUrlDoc( "aaa" );
        project.setUrlTechDoc( "aaa" );
        project.setProjectStatus( Project.PROJECTSTATUS_DISABLED );
        this.projectDAO.storeSubSet( project );

      SubSet subSet = new SubSet();
      subSet.setName( "uuu" );
      subSet.setAlias1( "aliasUuu1" );
      subSet.setAlias2( "aliasUuu2" );
      subSet.setAlias3( "aliasUuu3" );
      subSet.setProject( project );

      this.subSetDAO.storeSubSet(  subSet );
      //this.subSetDAO.deleteSubSet( subSet );

      subSet.setAlias2( "aliasUuuZ" );

      } catch( DataAccessException e ) {
      e.printStackTrace();
      fail();
    }
  }
}
